package com.yayo.mangement.authentication.context;

import com.yayo.mangement.info.UserInfo;

public class UserContext {

    private static final ThreadLocal<UserInfo> USER = new ThreadLocal<>();

    public static UserInfo getUser(){
        checkLogin();
        return USER.get();
    }

    public static Long getUserId(){
        checkLogin();
        return USER.get().getUserId();
    }

    private static void checkLogin(){
        if(USER.get() == null)
            throw new RuntimeException("");
    }

    public static void set(UserInfo userInfo){
        USER.set(userInfo);
    }

    public static void remove(){
        USER.remove();
    }

}
